<!DOCTYPE html>

<html lang="en">
<head>
     <!-- The jQuery library is a prerequisite for all jqSuite products -->
    <script type="text/ecmascript" src="../../../js/jquery.min.js"></script> 
    <!-- We support more than 40 localizations -->
    <script type="text/ecmascript" src="../../../js/trirand/i18n/grid.locale-en.js"></script>
    <!-- This is the Javascript file of jqGrid -->   
    <script type="text/ecmascript" src="../../../js/trirand/jquery.jqGrid.min.js"></script>
    <!-- A link to a Boostrap  and jqGrid Bootstrap CSS siles-->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> 
    <link rel="stylesheet" type="text/css" media="screen" href="../../../css/trirand/ui.jqgrid-bootstrap.css" />
	<script>
		$.jgrid.defaults.width = 780;
		$.jgrid.defaults.responsive = true;
		$.jgrid.defaults.styleUI = 'Bootstrap';
	</script>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <meta charset="utf-8" />
    <title>jqGrid Loading Data - Three Level Hierarchy</title>
</head>
<body>
<div style="margin-left:20px">
    <table id="jqGrid"></table>
    <div id="jqGridPager"></div>
</div>
    <script type="text/javascript"> 
    
        $(document).ready(function () {
            $("#jqGrid").jqGrid({
                url: 'data.json',
                mtype: "GET",
                datatype: "json",
                page: 1,
                colModel: [
                    { label: 'ID', name: 'CustomerID', key: true, width: 75 },
                    { label: 'Company Name', name: 'CompanyName', width: 150 },
                    { label: 'Contact Name', name: 'ContactName', width: 150 },
                    { label: 'Phone', name: 'Phone', width: 150 },
                    { label: 'City', name: 'City', width: 150 }
                ],
				loadonce: true,
                width: 780,
                height: 250,
                rowNum: 20,
                subGrid: true, // set the subGrid property to true to show expand buttons for each row
                subGridRowExpanded: showChildGrid, // javascript function that will take care of showing the child grid
                pager: "#jqGridPager"
            });
        });

        // the event handler on expanding parent row receives two parameters
        // the ID of the grid tow  and the primary key of the row
        function showChildGrid(parentRowID, parentRowKey) {
            var childGridID = parentRowID + "_table";
            var childGridPagerID = parentRowID + "_pager";

            // send the parent row primary key to the server so that we know which grid to show
            var childGridURL = parentRowKey+".json";

            // add a table and pager HTML elements to the parent grid row - we will render the child grid here
            $('#' + parentRowID).append('<table id=' + childGridID + '></table><div id=' + childGridPagerID + ' class=scroll></div>');

            $("#" + childGridID).jqGrid({
                url: childGridURL,
                mtype: "GET",
                datatype: "json",
                page: 1,
                colModel: [
                    { label: 'Order ID', name: 'OrderID', key: true, width: 75 },
                    { label: 'Required Date', name: 'RequiredDate', width: 100 },
                    { label: 'Ship Name', name: 'ShipName', width: 100 },
                    { label: 'Ship City', name: 'ShipCity', width: 100 },
                    { label: 'Freight', name: 'Freight', width: 75 }
                ],
				loadonce: true,
                width: '600',
                height: '150',
                subGrid: true, // set the subGrid property to true to show expand buttons for each row
                subGridRowExpanded: showThirdLevelChildGrid, // javascript function that will take care of showing the child grid
                pager: "#" + childGridPagerID
            });

        }

        // the event handler on expanding parent row receives two parameters
        // the ID of the grid tow  and the primary key of the row
        function showThirdLevelChildGrid(parentRowID, parentRowKey) {
            var childGridID = parentRowID + "_table";
            var childGridPagerID = parentRowID + "_pager";

            // send the parent row primary key to the server so that we know which grid to show
            var childGridURL = "child3.json";

            // add a table and pager HTML elements to the parent grid row - we will render the child grid here
            $('#' + parentRowID).append('<table id=' + childGridID + '></table><div id=' + childGridPagerID + ' class=scroll></div>');

            $("#" + childGridID).jqGrid({
                url: childGridURL,
                mtype: "GET",
                datatype: "json",
                colModel: [
                    { label: 'Order ID', name: 'OrderID', key: true, width: 75, hidden: true },
                    { label: 'Product ID', name: 'ProductID', width: 100 },
					{ label: 'Quantity', name: 'Quantity', width: 100 },
                    { label: 'Unit Price', name: 'UnitPrice', width: 100 },
					{ 
						label: 'Total', 
						name: 'Total', 
						width: 100, 
						sortable:false, 
						formatter: function( cellValue, options, row) {   // custom calculations at client side
							return parseFloat(row.Quantity)*parseFloat(row.UnitPrice);
						} 
					}
                ],
				loadonce: true,
                width: 'auto',
                height: '150',
                pager: "#" + childGridPagerID
            });

        }

    </script>

    <!-- This code is related to code tabs -->
    <br />
    <span style="margin-left:18px; font-family: Tahoma">Click on the Tabs below the see the relevant code for the example:</span>
    <br /><br />
    <div id="codetabs" style="width:700px; height: 400px; font-size:65%;"></div>
     
    <script type="text/ecmascript" src="../../../js/prettify/prettify.js"></script>
    <link rel="stylesheet" href="../../../css/prettify.css" />
        <script type="text/ecmascript" src="../../../js/codetabs-b.js"></script> 
    
    <script type="text/javascript">

        var tabData =
            [
                { name: "HTML", url: "index.html", lang: "lang-html" },
                { name: "Data", url: "data.json", lang: "lang-json" },
				{ name: "Subgrid Data", url: "ALFKI.json", lang: "lang-json" },
				{ name: "Description", url: "description.html", lang: "lang-html" }
            ];

        codeTabs(tabData);

    </script>
    <!-- End of code related to code tabs -->
</body>
</html>